package br.com.ps.bombertournament.game.scene;

import br.com.ps.bombertournament.SceneManager;
import br.com.ps.bombertournament.game.Layer;
import br.com.ps.bombertournament.game.Scene;
import br.com.ps.bombertournament.game.object.Label;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;

public class LoadingScene extends BaseScene {
	
	private Scene scene;
	private boolean renderCalled = false;
	
	public LoadingScene(Scene scene) {
		this.scene = scene;
	}
	
	@Override
	public void create(SceneManager sceneManager) {
		super.create(sceneManager);
		
		Layer loadingLayer = new Layer(getRenderer());
		
		{ // Adding the Label
			// TODO Add way to load international texts
			Label loadingLabel = new Label("loading...");

			float width = (float) (Gdx.graphics.getWidth() * 0.1);
			float height = (float) (Gdx.graphics.getHeight() * 0.1);
			float x = (Gdx.graphics.getWidth() / 2) - (width / 2);
			float y = height;
			
			loadingLabel.setBounds(x, y, width, height);
			
			loadingLayer.add(loadingLabel);
		}
		
		getRenderer().addLayer(1, loadingLayer);
	}

	@Override
	public void render(SpriteBatch spriteBatch) {
		if (renderCalled == false) {
			super.render(spriteBatch);
			renderCalled = true;
		} else {
			scene.create(super.getSceneManager());
			super.getSceneManager().setScene(scene);
		}
	}

	public void loadScene(Scene scene) {
		this.scene = scene;
		
		super.getSceneManager().setScene(this);
	}
}
